package com.all.play.myrecycleviewheadandfooter.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.all.play.myrecycleviewheadandfooter.R;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/5/15.
 * Time: 2018/5/15  9:10
 */

public class RvAdapter extends RecyclerView.Adapter<RvAdapter.MyViewHolder> {


    private Context context;
    private List<String> mData;
    private final LayoutInflater layoutInflater;

    public RvAdapter(Context context, List<String> mData) {
        layoutInflater = LayoutInflater.from(context);
        this.context = context;
        this.mData = mData;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        Log.i("onBindViewHolder", "onBindViewHolder: "+mData.size());
        holder.tv.setText(mData.get(position));


     }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }



    class MyViewHolder extends RecyclerView.ViewHolder{

        TextView tv;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv=itemView.findViewById(R.id.tv_item);
        }



    }




}
